<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>Document</title>
	<script type="text/javascript">
	function setCookie(name,value,iDay){
			var oDate=new Date();
			oDate.setDate(oDate.getDate()+iDay);
		document.cookie=name+'='+value+';expires='+oDate;
		}
         //setCookie('userName','liufanglei',365);
		//setCookie('passWord','123456',14);
         //alert(document.cookie);
//读取cookie
          function getCookie(name){
            var arr=document.cookie.split(';');
            for(var i=0;i<arr.length;i++){
            	var arr2=arr[i].split('=');
            	if(arr2[0]==name){
            		return arr2[1];
            	}
            }
            return ' ';
          }
           //  alert(getCookie('userName'));
          //删除cookie
          function removeCookie(name){
          	setCookie(name,1,-1);
          }
          //调用cookie,记住用户名
		window.onload=function (){
            var oForm=document.getElementById('form1');
            var oUser=document.getElementsByName('user')[0];
            oForm.onsubmit=function (){
            	setCookie('user',oUser.value,14);
            }
           oUser.value=getCookie('user');
		}
	</script>
</head>
<body>
	<form id="form1" action="http://www.baidu.com">
		用户名:<input type="text" name="user"><br>
		密码:<input type="password" name="pass"><br>
		<input type="submit" class="登陆">
	</form>
</body>
</html>